package org.linlinjava.litemall.db.service;

import java.time.LocalDateTime;
import java.util.List;

import javax.annotation.Resource;

import org.beetl.sql.core.query.LambdaQuery;
import org.linlinjava.litemall.db.domain.LitemallLog;
import org.linlinjava.litemall.db.mapper.LitemallLogDao;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class LitemallLogService {
    @Resource
    private LitemallLogDao logMapper;

    public void deleteById(Integer id) {
    	
    	LitemallLog log = new LitemallLog();
    	log.setId(id);
    	log.setDeleted(true);
    	logMapper.updateTemplateById(log);
        //logMapper.logicalDeleteByPrimaryKey(id);
    }

    public void add(LitemallLog log) {
        log.setAddTime(LocalDateTime.now());
        log.setUpdateTime(LocalDateTime.now());
        logMapper.insertTemplate(log,true);
        //logMapper.insertSelective(log);
    }

    public List<LitemallLog> querySelective(String name, Integer page, Integer size, String sort, String order) {
    	
    	LambdaQuery<LitemallLog> query = logMapper.createLambdaQuery();
    	
    	 if (!StringUtils.isEmpty(name)) {
    		 query.andLike(LitemallLog::getAdmin, "%" + name + "%");
         }
    	 
    	 query.andEq(LitemallLog::getDeleted, false);
    	 if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
    		 query.orderBy(sort + " " + order);
         }
    	 query.limit(page, size);
    	 return query.select();
			/*
			 * LitemallLogExample example = new LitemallLogExample();
			 * LitemallLogExample.Criteria criteria = example.createCriteria();
			 * 
			 * if (!StringUtils.isEmpty(name)) { criteria.andAdminLike("%" + name + "%"); }
			 * criteria.andDeletedEqualTo(false);
			 * 
			 * if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
			 * example.setOrderByClause(sort + " " + order); }
			 * 
			 * PageHelper.startPage(page, size); return logMapper.selectByExample(example);
			 */
    }
}
